package us.k5rud.template;

import android.content.Context;
import android.graphics.*;
import android.util.AttributeSet;
import android.util.Log;
import android.view.*;

public class TemplateSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
	private TemplateThread mTemplateThread;
	SurfaceHolder mHolder;

	private static final String TAG = "TemplateView";
	// -------------------------------------------------------------------------------------------------------
	public TemplateSurfaceView(Context context, AttributeSet attrs) {
		super(context, attrs);
		Log.v(TAG, "TemplateSurfaceView start");
		init();
		Log.v(TAG, "TemplateSurfaceView done");
	}
	// -------------------------------------------------------------------------------------------------------
	public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
		Log.v(TAG, "surfaceChanged start");
		Log.v(TAG, "surfaceChanged done");
	}
	// -------------------------------------------------------------------------------------------------------
	public void surfaceCreated(SurfaceHolder holder) {
		Log.v(TAG, "surfaceCreated start");
		Log.v(TAG, "surfaceCreated done");
	}
	// -------------------------------------------------------------------------------------------------------
	public void surfaceDestroyed(SurfaceHolder holder) {
		Log.v(TAG, "surfaceDestroyed start");
		Log.v(TAG, "surfaceDestroyed done");
	}
	// -------------------------------------------------------------------------------------------------------
	private void init() {
		Log.v(TAG, "init start");
		// Create a new SurfaceHolder and assign this class as its call back.
		mHolder = getHolder();
		mHolder.addCallback(this);

		Log.v(TAG, "init done");
	}
	// -------------------------------------------------------------------------------------------------------
	protected void doPause() {
		Log.v(TAG, "doPause start");
		mTemplateThread.pause();
		Log.v(TAG, "doPause done");
	}
	// -------------------------------------------------------------------------------------------------------
	protected void doResume() {
		mTemplateThread.unpause();
	}
	// -------------------------------------------------------------------------------------------------------
	protected void doStart() {
		Log.v(TAG, "doStart start");
		mTemplateThread = new TemplateThread(this, mHolder);
		mTemplateThread.start();
		Log.v(TAG, "doStart done");
	}
	// -------------------------------------------------------------------------------------------------------
	protected void doStop() {
		Log.v(TAG, "doStop start");
		mTemplateThread.die();
		mTemplateThread = null;
		Log.v(TAG, "doStop done");
	}
	// -------------------------------------------------------------------------------------------------------
	void doDraw(Canvas canvas) {
		Log.v(TAG, "draw start");
		Log.v(TAG, "draw done");
	}
}
